package com.comm.module;

import com.comm.base.BaseSubscriber;
import com.comm.module.bean.EventInfo;
import com.comm.module.bean.EventRequest;
import com.comm.module.bean.HttpResult;
import com.comm.utils.TransformUtils;

import java.util.List;
import java.util.concurrent.FutureTask;

import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by cxlin007 on 2017/10/6.
 */

public class ApiServiceImpl {

    private ApiService apiService;

    public ApiServiceImpl(ApiService apiService) {
        this.apiService = apiService;
    }

    public Subscription fetchEvents(BaseSubscriber subscriber) {
        EventRequest eventRequest = new EventRequest();
        eventRequest.page = "event_home";
        subscriber.onBeforeStart();
        Observable.Transformer<HttpResult<List<EventInfo>>, List<EventInfo>> httpTransform = TransformUtils.httpSchedulers();
        //数据预处理
        return apiService.fetchEvents(eventRequest)
                .compose(httpTransform)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }
}
